import 'package:situation/domain/common/MapLatLonDto.dart';
import 'package:situation/domain/common/UploadImageDto.dart';
import 'package:situation/shared/shared.dart';
import 'package:dio/dio.dart';

class BaseRequest {
  /**
   * 获取文件基本路径
   */
  static Future<String> getFilePrefix() async {
    var response = await UtilHttp().get(
      '/sysConfig/getConfig/base_file_url',
    );
    return response['data']['configValue'];
  }

  static Future savePosition(data) async {
    var response = await UtilHttp().post(
      '/dynamicPosition/savePosition',
      data: data
    );
    return response;
  }

  static Future getTeamUserPoints(queryParameters) async {
    var response = await UtilHttp().get(
      '/features/getTeamUserPoints',
      queryParameters: queryParameters
    );
    return response;
  }

  /**
   * path   文件的路径
   * 文件上传
   */
  static Future<UploadImageDto> uploadFile(path) async {
    var name = path.substring(path.lastIndexOf("/") + 1, path.length);
    String imageType = name.substring(name.lastIndexOf(".") + 1, name.length);
    var image = await MultipartFile.fromFile(
      path,
      filename: name + "." + imageType,
    );
    var response = await UtilHttp().postForm('/uploadFile/upload',
        data: {"file": image, "bucketName": "business", "key": name});
    return UploadImageDto.fromJson(response['data']);
  }

  static Future<MapLatLonDto>  getPositionName(double latitude, double longitude) async{
    var response = await UtilHttp().get(
        '/features/getAddressByLonLat?lon=${longitude}&lat=${latitude}',
    );
    return MapLatLonDto.fromJson(response['data']);
  }

}

